const app = getApp()
Page({
  data: {
 sign:"篮球",
 num:"0",
 array:[]
  },
  navagator(e){
    var that=this
    const appInstance = getApp()
       wx.request({
         url: 'https://www.linjianyi.link/judgeUser',
         data:{
          wxid:appInstance.globalData.oppenid,
         },
        success(res){
          //此时是一个新用户创建,所以直接调用wx.getUserProfile
         if(res.data=="NO"){
          wx.getUserProfile({
            // 声明获取用户个人信息后的用途，后续会展示在弹窗中，请谨慎填写
           desc: '用于完善会员资料',
           success: (res) => {
             console.log(res)
             //全局数据赋值
             appInstance.globalData.avatarUrl=res.userInfo.avatarUrl,
             appInstance.globalData.nickName=res.userInfo.nickName,
             appInstance.globalData.isActive=false
             wx.request({
               url: 'https://www.linjianyi.link/addconsumer',
               data:{
                 wxid:appInstance.globalData.oppenid,
                 name:appInstance.globalData.nickName,
                 img:appInstance.globalData.avatarUrl
               },
               success(res){
               }
             })
           }
         })
         }
         else{
           //进行界面跳转
          var id=e.currentTarget.dataset.shopid
          var imgg=that.data.array[id].img
          var messagee=that.data.array[id].category
      wx.navigateTo({
        url: '../../pages/activity/activity?message='+messagee+'&image='+imgg,
      })
           wx.request({
             url: 'https://www.linjianyi.link/getconsumer',
             data:{
              wxid:appInstance.globalData.oppenid
             },
             success(res){
       appInstance.globalData.avatarUrl=res.data[0][1],
       appInstance.globalData.nickName=res.data[0][2],
       appInstance.globalData.isActive=false
             }
           })
         }
        }
       })
    
 

  

  },
onShow:function(){
  var that=this;
  wx.request({
    url: 'https://www.linjianyi.link/getallCategory',    //这是Php文件的Url
    data: {  //前端向后端发送的数据
    },
    success(res) {
      that.setData({
        array:res.data,
      })
    }
  })
}
})
